package 两个有序数据重排;

public class Demo{

    /**
     * 2,6,7,10,13,15,18
     */
    public void test3(){
        int[] ary1 ={1,6,7,18};
        int[] ary2 ={2,8,9,10,15,20,28};
        int[] temp = new int[ary1.length+ary2.length];
        int i=0, j=0,k=0;
        while(i<ary1.length&&j<ary2.length){
            if(ary1[i]<ary2[j]){
                temp[k]=ary1[i];
                k++;
                i++;
            }else if(ary1[i]==ary2[j]){
                temp[k]=ary1[i];
                k++;
                i++;
                temp[k]=ary2[j];
                k++;
                j++;
            }else if(ary1[i]>ary2[j]){
                temp[k]=ary2[j];
                k++;
                j++;
            }
        }
        while(j<ary2.length){
            temp[k]=ary2[j];
            k++;
            j++;
        }
        while(i<ary1.length){
            temp[k]=ary1[i];
            k++;
            i++;
        }

        for(int o:temp){
            System.out.print(o+",");
        }
    }

    public static void main(String[] args){
        new Demo().test3();
    }

}